<?php
require_once('includes/common.php');

/*
$query = "SELECT * FROM `users` ";

$query = "SELECT `id`,`name`,`email` FROM `users` ";

$query = "SELECT `id`,`name`,`email` FROM `users` WHERE `name`='php'";

$query = "SELECT `id`,`name`,`email` FROM `users` WHERE `name`='php' ORDER BY `name` DESC ";

$query = "SELECT `id`,`name`,`email` FROM `users` WHERE `name`='php' ORDER BY `name` DESC LIMIT 0,1";
*/

//$result = fetchAll('users');
$result = fetchAll('users','','','','`uname`');
$result = fetchAll('users','','','','`uname`');
$result = fetchAll('users','','','LIMIT 2,2','`uname`,`id`');

while($ans = mysql_fetch_assoc($result)){
  pr($ans);
}

/*
  @param STRING $table = 'users'
  @param STRING $where = "WHERE `name`='php'"
  @param STRING $order = 'ORDER BY `name` DESC'
  @param STRING $limit = 'LIMIT 0,1'
  @param STRING $colName = '`id`,`name`,`email`'
  @return $result STREAM(resource)
*
*/
function fetchAll($table='',$where='',$order='',$limit='',$colName=''){

  $colName = ($colName=='') ? '*' :$colName;
  $query = "SELECT $colName FROM `$table` $where $order $limit";
  vx($query);
  $result = mysql_query($query) or die(mysql_error());
  return $result;
}

